import store from "../store";

export const mixin= {
  methods: {
    notify(title, type) {
      this.$notify({
        title: title,
        type: type
      })
    },
    // 根据相对地址，获取绝对地址
    getImgUrl(url) {
      return `${this.$store.state.HOST}/${url}`
    },
    // 根据得到的性别0,1数据，变更为中文男女
    ChangeSex(value) {
      if (value == 0) {
        return '女'
      } else if (value == 1) {
        return '男'
      }
    },
    // 获取生日格式
    attachBirth(val) {
      return String(val).substr(0, 10)
    },
    // 歌手上传图片之前的校验
    beforeSingerAvatorUpload(file) {
      const isJPG = (file.type === 'image/jpeg') || (file.type === 'image/png');
      if (!isJPG) {
        this.$message.error('上传头像图片只能是jpg或png格式');
        return false;
      }
      const isLT2M = (file.size / 1024 / 1024) < 2;
      if (!isLT2M) {
        this.$message.error('上传头像图片大小不能超过2MB');
        return false;
      }
      return true;
    },
    // 歌手上传图片成功后
    handleSingerAvatorSuccess(res) {
      let _this = this;
      if (res.code == 1) {
        _this.getSingerDate();
        this.$message.success('上传成功')
      } else {
        this.$message.error('上传失败')
      }
    },
    // 歌曲上传图片之前的校验
    beforeSongAvatorUpload(file) {
      const isJPG = (file.type === 'image/jpeg') || (file.type === 'image/png');
      if (!isJPG) {
        this.$message.error('上传头像图片只能是jpg或png格式');
        return false;
      }
      const isLT2M = (file.size / 1024 / 1024) < 2;
      if (!isLT2M) {
        this.$message.error('上传头像图片大小不能超过2MB');
        return false;
      }
      return true;
    },
    // 歌曲上传图片成功后
    handleSongAvatorSuccess(res) {
      let _this = this;
      if (res.code == 1) {
        _this.getSongDate();
        this.$message.success('上传成功')
      } else {
        this.$message.error('上传失败')
      }
    },
    // 歌单上传图片之前的校验
    beforeSongListAvatorUpload(file) {
      const isJPG = (file.type === 'image/jpeg') || (file.type === 'image/png');
      if (!isJPG) {
        this.$message.error('上传头像图片只能是jpg或png格式');
        return false;
      }
      const isLT2M = (file.size / 1024 / 1024) < 2;
      if (!isLT2M) {
        this.$message.error('上传头像图片大小不能超过2MB');
        return false;
      }
      return true;
    },
    // 歌单上传图片成功后
    handleSongListAvatorSuccess(res) {
      let _this = this;
      if (res.code == 1) {
        _this.getSongListDate();
        this.$message.success('上传成功')
      } else {
        this.$message.error('上传失败')
      }
    },
    // 前台用户上传图片之前的校验
    beforeConsumerAvatorUpload(file) {
      const isJPG = (file.type === 'image/jpeg') || (file.type === 'image/png');
      if (!isJPG) {
        this.$message.error('上传头像图片只能是jpg或png格式');
        return false;
      }
      const isLT2M = (file.size / 1024 / 1024) < 2;
      if (!isLT2M) {
        this.$message.error('上传头像图片大小不能超过2MB');
        return false;
      }
      return true;
    },
    // 前台用户上传图片成功后
    handleConsumerAvatorSuccess(res) {
      let _this = this;
      if (res.code == 1) {
        _this.getConsumerDate();
        this.$message.success('上传成功')
      } else {
        this.$message.error('上传失败')
      }
    },
    // 删除歌手
    handleDelete(id) {
      this.idx = id
      this.DeleteVisible = true
    },
    // 批量删除，传输已选择的项
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 批量歌手删除，删除已选择的项
    deleteSingerAll() {
      for (let item of this.multipleSelection) {
        this.handleDelete(item.id)
        this.DelteSingerRow()
      }
      this.multipleSelection = []
    },
    // 批量歌单删除，删除已选择的项
    deleteSongListAll() {
      for (let item of this.multipleSelection) {
        this.handleDelete(item.id)
        this.DelteSongListRow()
      }
      this.multipleSelection = []
    },
    // 批量歌单歌曲删除，删除已选择的项
    deleteListSongAll() {
      for (let item of this.multipleSelection) {
        this.handleDelete(item.id)
        this.DelteListSongRow()
      }
      this.multipleSelection = []
    },
    // 批量歌曲删除，删除已选择的项
    deleteSongAll() {
      for (let item of this.multipleSelection) {
        this.handleDelete(item.id)
        this.DelteSongRow()
      }
      this.multipleSelection = []
    },
    // 批量前台用户删除，删除已选择的项
    deleteConsumerAll() {
      for (let item of this.multipleSelection) {
        this.handleDelete(item.id)
        this.DelteConsumerRow()
      }
      this.multipleSelection = []

    }
  }
}
























